package com.sunday.android.fangdaifu.bukong.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.squareup.picasso.Picasso;
import com.sunday.android.fangdaifu.bukong.R;
import com.sunday.android.fangdaifu.bukong.utils.ShowBigImage;
import com.sunday.common.utils.DeviceUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yun_sheng on 2017/7/7.
 * 建筑详情图片
 */

public class BuilderDetailImageAdapter extends RecyclerView.Adapter implements View.OnClickListener {

    private Context mContext;
    private ArrayList<String> list;

    int w,h;

    public BuilderDetailImageAdapter(Context mContext, ArrayList<String> list) {
        this.mContext = mContext;
        this.list = list;
        w = DeviceUtils.getDisplay(mContext).widthPixels;
        h = DeviceUtils.getDisplay(mContext).heightPixels;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.image01, null);
        return new MyHolder(view);
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyHolder myHolder = (MyHolder) holder;
        Picasso.with(mContext)
                .load(list.get(position))
                .placeholder(R.drawable.default_error)
                .resize(200,200)
                .error(R.drawable.default_error)
                .into(myHolder.image);
        myHolder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, ShowBigImage.class);
                intent.putStringArrayListExtra("data",list);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void onClick(View v) {

    }

    public class MyHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.image)
        ImageView image;
        public MyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams((int) (w*0.62), w/2-20);
            image.setLayoutParams(layoutParams);
        }
    }
}
